package com.yyfax.ph.personal.settings;

import com.yyfax.common.CLog;
import com.yyfax.infrastructure.eventbus.EventAgent;
import com.yyfax.infrastructure.mvp.IView;
import com.yyfax.infrastructure.mvp.Presenter;
import com.yyfax.infrastructure.mvp.PresenterFactory;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

public class GetCompanyPresenter extends Presenter<GetCompanyModel, GetCompanyPresenter.View> {
	private static final String TAG = GetCompanyPresenter.class.getSimpleName();
	

	public static class Generator implements PresenterFactory<GetCompanyPresenter> {
		@Override
		public GetCompanyPresenter create() {
			return new GetCompanyPresenter();
		}
	}

	private View mView;

	@Override
	public void attach(View view) {
		mView = view;
		mModel = new GetCompanyModel();
		EventAgent.register(this);
	}

	@Override
	public void detach() {
		mView = null;
		mModel = null;
		EventAgent.unregister(this);
	}

	public interface View extends IView {
		void getCompanySuccess(String status, String company, String phone);
	}

	/**
	 * 获取所属公司
	 */
	public void getBindCompany() {
		CLog.i(TAG, "getBindCompany");
		execute(null, GetCompanyModel.MSG_CHECK_BIND_COMPANY);

	}

	@Subscribe(threadMode = ThreadMode.MAIN)
	public void getCompanyResult(GetCompanyModel.CompanyResult companyResult) {
		CLog.i(TAG, "getCompanyResult = " + companyResult.toString());
		if (isResponseSuccess(companyResult)) {
			GetCompanyModel.CompanyBean bean = companyResult.getContent();
			String status = bean.status.trim();
			String company = "";
			if (GetCompanyModel.STATUS_BIND.equals(status))
				company = bean.companyName;
			else if (GetCompanyModel.STATUS_APPLYING.equals(status))
				company = bean.applyName;
			mView.getCompanySuccess(status, company, bean.phone);
		}
	}
}
